package com.data.platform.core.enums;

import cn.hutool.core.convert.ConvertException;

/**
 * 数据大小
 */
public enum DataSize {
    B {
        @Override
        public double toByte(long number) {
            return number;
        }

        @Override
        public double toKilobyte(long number) {
            return number / 1024.0;
        }

        @Override
        public double toMegabyte(long number) {
            return number / 1024.0 / 1024;
        }

        @Override
        public double toGigabyte(long number) {
            return number / 1024.0 / 1024 / 1024;
        }
    },

    KB {
        @Override
        public double toByte(long number) {
            return number * 1024.0;
        }

        @Override
        public double toKilobyte(long number) {
            return number;
        }

        @Override
        public double toMegabyte(long number) {
            return number / 1024.0;
        }

        @Override
        public double toGigabyte(long number) {
            return number / 1024.0 / 1024;
        }
    },

    MB {
        @Override
        public double toByte(long number) {
            return number * 1024.0 * 1024;
        }

        @Override
        public double toKilobyte(long number) {
            return number * 1024.0;
        }

        @Override
        public double toMegabyte(long number) {
            return number;
        }

        @Override
        public double toGigabyte(long number) {
            return number / 1024.0;
        }
    },

    GB {
        @Override
        public double toByte(long number) {
            return number * 1024.0 * 1024 * 1024;
        }

        @Override
        public double toKilobyte(long number) {
            return number * 1024.0 * 1024;
        }

        @Override
        public double toMegabyte(long number) {
            return number * 1024.0;
        }

        @Override
        public double toGigabyte(long number) {
            return number;
        }
    };

    public double toByte(long number) {
        throw new ConvertException("转换B失败");
    }

    public double toKilobyte(long number) {
        throw new ConvertException("转换KB失败");
    }

    public double toMegabyte(long number) {
        throw new ConvertException("转换MB失败");
    }

    public double toGigabyte(long number) {
        throw new ConvertException("转换GB失败");
    }
}
